package com.mid;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * Created by Lxk on 2020/1/28.
 */
public class Solution199 {

    private Map<Integer, Integer> depthValue = new TreeMap<>();

    private void dfs(TreeNode node, Integer depth) {
        if (node == null) {
            return;
        }
        if (depthValue.get(depth) == null) {
            depthValue.put(depth, node.val);
        }
        dfs(node.right, depth + 1);
        dfs(node.left, depth + 1);
    }

    public List<Integer> rightSideView(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        dfs(root, 0);
        for (Map.Entry<Integer, Integer> entry : depthValue.entrySet()) {
            res.add(entry.getValue());
        }
        return res;
    }

}
